package com.party.mobile.web.controller.crowdfund;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.party.authorization.annotation.Authorization;
import com.party.common.constant.Constant;
import com.party.common.paging.Page;
import com.party.common.utils.BigDecimalUtils;
import com.party.common.utils.PartyCode;
import com.party.common.utils.StringUtils;
import com.party.core.exception.BusinessException;
import com.party.core.model.YesNoStatus;
import com.party.core.model.activity.Activity;
import com.party.core.model.audio.Audio;
import com.party.core.model.counterfoil.Counterfoil;
import com.party.core.model.crowdfund.*;
import com.party.core.model.member.Member;
import com.party.core.model.system.TargetType;
import com.party.core.service.activity.IActivityService;
import com.party.core.service.audio.IAudioService;
import com.party.core.service.cos.CosBizService;
import com.party.core.service.counterfoil.ICounterfoilService;
import com.party.core.service.crowdfund.*;
import com.party.core.service.member.IMemberService;
import com.party.core.service.system.ISysConfigService;
import com.party.core.service.wechat.IWechatAccountService;
import com.party.mobile.biz.crowdfund.ProjectBizService;
import com.party.mobile.biz.crowdfund.ProjectTransferNewBizService;
import com.party.mobile.biz.currentUser.CurrentUserBizService;
import com.party.mobile.biz.file.FileBizService;
import com.party.mobile.biz.wechat.WechatBizService;
import com.party.mobile.web.annotation.VisitCollect;
import com.party.mobile.web.dto.AjaxResult;
import com.party.mobile.web.dto.crowdfund.input.SupportInput;
import com.party.mobile.web.dto.crowdfund.output.*;
import com.party.mobile.web.dto.login.output.CurrentUser;
import com.vdurmont.emoji.EmojiParser;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.*;

/**
 * 众筹控制器
 * Created by wei.li
 *
 * @date 2017/2/17 0017
 * @time 9:43
 */

@SuppressWarnings("all")
@Controller
@RequestMapping(value = "crowdfund/project")
public class ProjectController {

    @Autowired
    private ProjectBizService projectBizService;

    @Autowired
    private CurrentUserBizService currentUserBizService;

    @Autowired
    private IProjectService projectService;

    @Autowired
    private WechatBizService wechatBizService;

    @Autowired
    private IWechatAccountService wechatAccountService;

    @Autowired
    private FileBizService fileBizService;

    @Autowired
    private ICrowdfundRankService crowdfundRankService;

    @Autowired
    private ITargetProjectService targetProjectService;

    @Autowired
    private ISupportService supportService;

    @Autowired
    private IActivityService activityService;

    @Autowired
    private ISysConfigService sysConfigService;

    @Autowired
    private ICrowdfundEventService crowdfundEventService;

    @Autowired
    private CosBizService cosBizService;

    @Autowired
    private IAudioService audioService;

    @Autowired
    private IProjectInfoGradationService projectInfoGradationService;

    @Autowired
    private ICounterfoilService counterfoilService;

    @Autowired
    private ProjectTransferNewBizService projectTransferNewBizService;


    private static Logger logger = LoggerFactory.getLogger(ProjectController.class);

    /**
     * 项目列表
     *
     * @param type      列表类型（0:我众筹的 1:我支持的）
     * @param page      分页参数
     * @param isSuccess 众筹状态
     * @return
     */
    @Authorization
    @ResponseBody
    @RequestMapping(value = "list")
    @VisitCollect(module = TargetType.ZC_ACTIVITY)
    public AjaxResult list(Integer type, Integer isSuccess, Page page, HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();
        CurrentUser currentUser = currentUserBizService.getCurrentUser(request);
        List<ProjectListOutput> projectListOutputList = null;
        try {
            projectListOutputList = projectBizService.list(type, isSuccess, page, currentUser.getId());
        } catch (Exception e) {
            logger.error("项目列表异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectListOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 转移支持者
     *
     * @param
     * @param
     * @return 交互数据
     */
    @ResponseBody
    @Authorization
    @RequestMapping(value = "dataTransfer")
    public AjaxResult dataTransferm(String sourceId, String targetId, HttpServletRequest request) {
        return projectTransferNewBizService.transferSupport(sourceId, targetId, request);
    }

    /**
     * 获取众筹项目详情
     *
     * @param id 项目编号
     * @return 项目详情
     */
    @Authorization
    @ResponseBody
    @RequestMapping(value = "getDetails")
    @VisitCollect(module = TargetType.ZC_ACTIVITY)
    public AjaxResult getDetails(String id, HttpServletRequest request) {
        AjaxResult ajaxResult = new AjaxResult();

        //验参
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }

        CurrentUser currentUser = currentUserBizService.getCurrentUser(request);
        ProjectInfoGradation byProjectId = projectInfoGradationService.findByProjectId(id);
        ProjectOutput projectOutput = null;
        try {
            if (byProjectId != null) {
                throw new BusinessException(PartyCode.IS_NO_DATA, "该众筹是多场活动的");
            }
            projectOutput = projectBizService.getDetails(id, currentUser);
            if (StringUtils.isNotEmpty(projectOutput.getDeclaration())) {
                if (sysConfigService.isConvertBase64()) {
                    projectOutput.setDeclaration(StringUtils.decodeBase64New(projectOutput.getDeclaration()));
                } else {
                    projectOutput.setDeclaration(EmojiParser.parseToUnicode(projectOutput.getDeclaration()));
                }
            }
        } catch (BusinessException be) {
            ajaxResult.setErrorCode(be.getCode());
            ajaxResult.setDescription(be.getMessage());
            return ajaxResult;
        } catch (Exception e) {
            ajaxResult.setDescription("获取详情异常");
            return ajaxResult;
        }
        Activity activity = activityService.get(projectOutput.getTargeId());


        //二维码
        String filePath = fileBizService.getUploadCIPath("crowdfund", projectOutput.getAuthorId());
        String qrCodeUrl = cosBizService.getPreviewPictureUrl(filePath + projectOutput.getId());
        projectOutput.setQrcodeUrl(qrCodeUrl);

//        ProjectWithAuthor project = projectService.getWithAuthor(id);
//        String filePath = fileBizService.getUploadCIPath("crowdfund", project.getAuthorId());
//        String content = "project/project_detail.html?id=" + id;
//        String qrcodeUrl = fileBizService.uploadCloudOut(id, filePath, content, activity.getMember());
//        projectOutput.setQrcodeUrl(qrcodeUrl);
        CrowdfundEvent crowdfundEvent = crowdfundEventService.getCorwdfundByActivityId(projectOutput.getTargeId());
        projectOutput.setIsProblem(crowdfundEvent.getIsProblem());
        projectOutput.setPersonalRanking(crowdfundEvent.getPersonalRanking());
        projectOutput.setPersonalPopularPageState(activity.getPersonalPopularPageState());

        if (3 == activity.getPersonalPopularPageState()) {
            //3代表该众筹者的支持者
            projectOutput.setTeamName("支持者");
        }
        if (1 == activity.getPersonalPopularPageState()) {
            //1代表显示该项目报名人员
            projectOutput.setTeamName(activity.getPublisher());
        }
        if (0 == activity.getPersonalPopularPageState()) {
            //0代表显示所属主题报名人员
            projectOutput.setTeamName("同行队友");
        }
        if (0 == crowdfundEvent.getStrategyState()) {
            //显示众筹攻略
            if (currentUser.getId().equals(projectOutput.getAuthorId())) {
                //如果登入人和报名人不是同一个人，就不显示众筹攻略
                projectOutput.setStrategyState(0);
            } else {
                projectOutput.setStrategyState(1);
            }
        } else {
            projectOutput.setStrategyState(1);
        }
        // 众筹项目详情二维码
        String targetFilePath = fileBizService.getUploadCIPath(activity.getMember(), "zcActivity");
        String detailFileName = "detail_" + activity.getId();
        String detailQrCodeUrl = cosBizService.getPreviewPictureUrl(targetFilePath + detailFileName);
        projectOutput.setTargetQrCode(detailQrCodeUrl);

        List<Counterfoil> counterfoils = counterfoilService.findByBusinessId(crowdfundEvent.getId(), Constant.BUSINESS_TYPE_CROWDFUND);
        projectOutput.setCounterfoils(counterfoils);
        //是否播放音乐(0否/是)
        Integer isPlayMusic = 0;
        //音频url
        String audioUrl = "";
        try {
            Audio audio = audioService.findAudioByEventId(activity.getEventId());
            if (null != audio) {
                isPlayMusic = 1;
                audioUrl = audio.getAudioUrl();
            }
        } catch (Exception e) {
            logger.info("众筹项目详情页H5,音频获取失败", e.getMessage());
        }
        projectOutput.setIsPlayMusic(isPlayMusic);
        projectOutput.setAudioUrl(audioUrl);
        projectOutput.setJoinNum(activity.getJoinNum());

        List<CrowdfundingBattleReport> cbrList = new ArrayList<>();

        try {
            //众筹成功战报
            HashMap<String, Object> param = Maps.newHashMap();
            param.put("eventId",activity.getEventId());
            param.put("isSuccess",1);
            List<CrowdfundingBattleReport> projectBattleReport_suc = projectService.getProjectBattleReport(
                    param,
                    CrowdfundingBattleReport.CBR_TYPE_C_SUCCESS);
            cbrList.addAll(projectBattleReport_suc);

            //众筹报名战报
            param.clear();
            param.put("eventId",activity.getEventId());
            List<CrowdfundingBattleReport> projectBattleReport_sucIng = projectService.getProjectBattleReport(
                    param,
                    CrowdfundingBattleReport.CBR_TYPE_C_APPLY);
            cbrList.addAll(projectBattleReport_sucIng);

            //支持战报
            List<CrowdfundingBattleReport> supportBattleReport = supportService.getSupportBattleReport(
                    activity.getEventId(),
                    CrowdfundingBattleReport.CBR_TYPE_C_SUPPORT);
            cbrList.addAll(supportBattleReport);
        }catch (Exception e){
            logger.info("查询众筹战报失败", e);
        }
        projectOutput.setCbrList(cbrList);

        return AjaxResult.success(projectOutput);
    }

    /**
     * 众筹支持
     *
     * @param supportInput 输入视图
     * @param result       参数验证
     * @return 支持结果
     */
    @Authorization
    @ResponseBody
    @RequestMapping(value = "support")
    public AjaxResult support(@Validated SupportInput supportInput, BindingResult result, HttpServletRequest request) {
        //数据验证
        AjaxResult ajaxResult = new AjaxResult();
        if (result.hasErrors()) {
            List<ObjectError> allErrors = result.getAllErrors();
            String description = allErrors.get(0).getDefaultMessage();
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription(description);
            return ajaxResult;
        }
        CurrentUser currentUser = currentUserBizService.getCurrentUser(request);
        String orderId = null;
        String supportId = null;
        try {
            String[] ids = projectBizService.support(supportInput, currentUser);
            orderId = ids[0];
            supportId = ids[1];
        } catch (BusinessException be) {
            ajaxResult.setErrorCode(be.getCode());
            ajaxResult.setDescription(be.getMessage());
            return ajaxResult;
        } catch (Exception e) {
            logger.error("支持异常---supportInput：" + JSONObject.toJSONString(supportInput), e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        SupportOrderOutput supportOrderOutput = new SupportOrderOutput(orderId);
        supportOrderOutput.setSupportId(supportId);
        ajaxResult.setData(supportOrderOutput);
        return ajaxResult;
    }


    /**
     * 直接付款众筹 支持订单
     *
     * @param supportInput 输入视图
     * @param result       参数验证
     * @return 支持结果
     */
    @Authorization
    @ResponseBody
    @RequestMapping(value = "supportDirectPay")
    public AjaxResult supportDirectPay(@Validated SupportInput supportInput,
                                       BindingResult result, HttpServletRequest request) {
        //数据验证
        AjaxResult ajaxResult = new AjaxResult();
        if (result.hasErrors()) {
            List<ObjectError> allErrors = result.getAllErrors();
            String description = allErrors.get(0).getDefaultMessage();
            if (!description.equals("金额不能为空")) {// 不对众筹金额进行验证
                ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
                ajaxResult.setDescription(description);
                return ajaxResult;
            }
        }

        Project project = projectService.get(supportInput.getProjectId());//查询当前众筹
        String authorId = project.getAuthorId();//查询活动发起者
        CurrentUser currentUser = currentUserBizService.getCurrentUser(request);
        logger.info("当前用户id:{},众筹发布者id:{}", currentUser.getId(), authorId);
        if (project.getPayType() == Constant.IS_DIRECTPAY_CROWDFUNDED) {//直接付款众筹
            if (currentUser != null && !authorId.equals(currentUser.getId())) {
                ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);//不符合自己支持自己的业务规则
                ajaxResult.setDescription("不符合自己支持自己的业务规则");
                return ajaxResult;
            }
        }

        Support support = new Support();
        support.setProjectId(project.getId());
        SupportWithMember resultSupport = supportService.getLastSupport(support);
        if (resultSupport != null && resultSupport.getPayStatus() == 0) {//防止重复支付
            SupportOrderOutput supportOrderOutput = new SupportOrderOutput(resultSupport.getOrderId());
            supportOrderOutput.setSupportId(resultSupport.getId());//返回支持者订单ID
            ajaxResult.setSuccess(true);
            ajaxResult.setData(supportOrderOutput);
            return ajaxResult;
        }
//        support.setPayStatus(1);
        //支持者订单与支付订单的联合查询结果
        if (resultSupport != null && resultSupport.getPayStatus() == 1 && project.getIsSuccess() == 1) {//已支付订单不能再次支付
            ajaxResult.setErrorCode(PartyCode.PAYMENT_STATUS_ERROR);//已支付订单不能再次支付
            ajaxResult.setDescription("订单已支付，不能再次支付");
            return ajaxResult;
        }
//        if (resultSupport!=null && (resultSupport.getPayStatus() == 1 && resultSupport.getPayment() == project.getTargetAmount())
//                || project.getIsSuccess() == 1
//                || project.getActualAmount() == project.getTargetAmount()) {//已支付订单不能再次支付
//            ajaxResult.setErrorCode(PartyCode.PAYMENT_STATUS_ERROR);//已支付订单不能再次支付
//            ajaxResult.setDescription("订单已支付，不能再次支付");
//            return ajaxResult;
//        }

        String orderId = null;//支付订单ID
        String supportId = null;//支持者订单ID
        try {
            supportInput.setMoney(project.getTargetAmount());
            String[] ids = projectBizService.support(supportInput, currentUser);
            orderId = ids[0];
            supportId = ids[1];
        } catch (BusinessException be) {
            ajaxResult.setErrorCode(be.getCode());
            ajaxResult.setDescription(be.getMessage());
            return ajaxResult;
        } catch (Exception e) {
            logger.error("直接付款 支持异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        SupportOrderOutput supportOrderOutput = new SupportOrderOutput(orderId);
        supportOrderOutput.setSupportId(supportId);
//        supportOrderOutput.setTotalAmount(project.getTargetAmount());//将活动目标金额作为众筹金额
        ajaxResult.setData(supportOrderOutput);//将报名的支持订单ID与支付订单ID及 众筹金额 回传给前端页面
        return ajaxResult;
    }


    /**
     * 删除众筹
     *
     * @param id 众筹编号
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "delete")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public AjaxResult delete(String id) {
        logger.info("-------当前取消众筹订单-------" + id);
        if (StringUtils.isEmpty(id))
            return AjaxResult.error(500, "请输入众筹ID");
        boolean result = projectBizService.delete(id);
        logger.info("-------当前取消众筹订单结果：" + result);
        if (result) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }


    /**
     * 获取剩余资金
     *
     * @param id 众筹编号
     * @return 剩余资金
     */
    @ResponseBody
    @RequestMapping(value = "getMaxAmount")
    public AjaxResult getMaxAmount(String id) {
        try {
            Double amount = projectService.getMaxAmount(id);
            return AjaxResult.success(amount);
        } catch (Exception e) {
            logger.error("获取剩余资金异常", e);
            return AjaxResult.error(100, "获取剩余资金异常");
        }
    }

    /**
     * 众筹中的众筹
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "crowdfunding")
    public AjaxResult crowdfunding(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.projectForActivityList(false, id, page);
        } catch (Exception e) {
            logger.error("获取众筹中异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 众筹成功的众筹
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "crowdfunded")
    public AjaxResult crowdfunded(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.projectForActivityList(true, id, page);
        } catch (Exception e) {
            logger.error("获取众筹成功数据异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 众筹中的众筹
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "crowdfundingForBrother")
    public AjaxResult crowdfundingForBrother(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.projectForBrotherList(false, id, page);
        } catch (Exception e) {
            logger.error("crowdfundingForBrother异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 众筹成功的众筹
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "crowdfundedForBrother")
    public AjaxResult crowdfundedForBrother(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.projectForBrotherList(true, id, page);
        } catch (Exception e) {
            logger.error("crowdfundedForBrother异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }


    /**
     * 所属活动事件所有众筹（众筹中）
     *
     * @param id   活动编号
     * @param page 分页参数
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "crowdfundingForAll")
    public AjaxResult crowdfundingForAll(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.projectForAllList(false, id, page);
        } catch (Exception e) {
            logger.error("crowdfundingForAll异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 所属活动事件所有众筹(已经筹满)
     *
     * @param id   活动编号
     * @param page 分页参数
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "crowdfundedForAll")
    public AjaxResult crowdfundedForAll(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.projectForAllList(true, id, page);
        } catch (Exception e) {
            logger.error("crowdfundedForAll异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 众筹中的众筹
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "representCrowdfunding")
    public AjaxResult representCrowdfunding(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.projectForRepresentList(false, id, page);
        } catch (Exception e) {
            logger.error("representCrowdfunding异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 众筹成功的众筹
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "represencrowdfunded")
    public AjaxResult represencrowdfunded(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.projectForRepresentList(true, id, page);
        } catch (Exception e) {
            logger.error("represencrowdfunded异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }


    /**
     * 支持我的众筹中
     *
     * @param id   众筹编号
     * @param page 分页参数
     * @return 众筹列表
     */
    @ResponseBody
    @RequestMapping(value = "supportCrowdfunding")
    public AjaxResult supportCrowdfunding(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹编号不能为空");
            return ajaxResult;
        }

        List<ProjectForActivityOutput> projectForActivityOutputList;
        try {
            projectForActivityOutputList = projectBizService.supportProjectList(false, id, page);
        } catch (Exception e) {
            logger.error("supportCrowdfunding异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 支持我的已经筹满
     *
     * @param id   众筹编号
     * @param page 分页参数
     * @return 众筹列表
     */
    @ResponseBody
    @RequestMapping(value = "supportCrowdfunded")
    public AjaxResult supportCrowdfunded(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹编号不能为空");
            return ajaxResult;
        }

        List<ProjectForActivityOutput> projectForActivityOutputList;
        try {
            projectForActivityOutputList = projectBizService.supportProjectList(true, id, page);
        } catch (Exception e) {
            logger.error("supportCrowdfunded异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 支持者的所有众筹(众筹中和已筹满)
     *
     * @param id   众筹编号
     * @param page 分页参数
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "supportCrowdfundAll")
    public AjaxResult supportCrowdfundAll(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹编号不能为空");
            return ajaxResult;
        }

        List<ProjectForActivityOutput> projectForActivityOutputList;
        try {
            projectForActivityOutputList = projectBizService.supportProjectList(id, page);
        } catch (Exception e) {
            logger.error("supportCrowdfundAll异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 获取众筹项目最大支持金额
     *
     * @param id 项目编号
     * @return 支持金额
     */
    @ResponseBody
    @RequestMapping(value = "getSupportInit")
    @VisitCollect(module = TargetType.ZC_ACTIVITY)
    public AjaxResult getSupportInit(String id) {
        AjaxResult ajaxResult = new AjaxResult();
        //验参
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }

        GetSupportInitOutput getSupportInitOutput;
        try {
            getSupportInitOutput = projectBizService.getSupportInit(id);
            if (StringUtils.isNotEmpty(getSupportInitOutput.getSupportDeclaration())) {
                if (sysConfigService.isConvertBase64()) {
                    getSupportInitOutput.setSupportDeclaration(StringUtils.decodeBase64New(getSupportInitOutput.getSupportDeclaration()));
                } else {
                    getSupportInitOutput.setSupportDeclaration(EmojiParser.parseToUnicode(getSupportInitOutput.getSupportDeclaration()));
                }
            }
        } catch (BusinessException be) {
            ajaxResult.setDescription(be.getMessage());
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(getSupportInitOutput);
        return ajaxResult;
    }


    /**
     * 编辑众筹项目
     *
     * @param id          众筹编号
     * @param declaration 众筹宣言
     * @return 加护数据
     */
    @ResponseBody
    @RequestMapping(value = "edite")
    public AjaxResult edite(String id, String declaration, String style) {
        AjaxResult ajaxResult = new AjaxResult();
        try {
            if (StringUtils.isNotEmpty(declaration)) {
                if (sysConfigService.isConvertBase64()) {
                    declaration = StringUtils.encodeBase64(declaration);
                } else {
                    declaration = EmojiParser.parseToAliases(declaration);
                }
            }
            projectBizService.edite(id, declaration, style);
        } catch (Exception e) {
            e.printStackTrace();
            ajaxResult.setDescription("服务器异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        return ajaxResult;
    }

    @ResponseBody
    @RequestMapping(value = "createQrCode")
    public AjaxResult createQrCode(String projectId, HttpServletRequest request) {
        if (StringUtils.isEmpty(projectId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "projectId不能为空");
        }
        try {
            ProjectWithAuthor project = projectService.getWithAuthor(projectId);

            TargetProject targetProject = targetProjectService.findByProjectId(projectId);
            Activity activity = activityService.get(targetProject.getTargetId());

            String qrcodeUrl = "";
            CrowdfundEvent crowdfundEvent = crowdfundEventService.get(activity.getEventId());
            if (YesNoStatus.YES.getCode().equals(crowdfundEvent.getIsMultiple())) {
                String filePath = fileBizService.getUploadCIPath("crowdfund", project.getAuthorId());
                String content = "project/project_multi_detail.html?id=" + projectId;
                qrcodeUrl = fileBizService.uploadCloudOut(projectId, filePath, content, activity.getMember());
            } else {
                String filePath = fileBizService.getUploadCIPath("crowdfund", project.getAuthorId());
                String content = "project/project_detail.html?id=" + projectId;
                qrcodeUrl = fileBizService.uploadCloudOut(projectId, filePath, content, activity.getMember());
            }

            Map<String, Object> result = Maps.newHashMap();
            result.put("qrcodeUrl", qrcodeUrl);
            result.put("project", project);
            logger.info("结果：{}", JSONObject.toJSONString(result));
            return AjaxResult.success(result);
        } catch (Exception e) {
            logger.error("生成二维码异常", e);
            return AjaxResult.error(100, e.getMessage());
        }
    }


    /**
     * 获取众筹排名
     *
     * @param projectId 众筹id
     * @param targetId  众筹项目id
     * @return
     */
    @ResponseBody
    @RequestMapping("getCrowdRank")
    @VisitCollect(module = TargetType.ZC_ACTIVITY)
    public AjaxResult getCrowdRank(String projectId, String targetId) {
        if (StringUtils.isEmpty(projectId) || StringUtils.isEmpty(targetId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "id不能为空");
        }
        // 获取排名
        List<CrowdfundRank> crowdfundRanks = Lists.newArrayList();
        for (int i = 1; i < 11; i++) {
            CrowdfundRank percent1 = crowdfundRankService.getCrowdRank(new CrowdfundRank("", targetId, projectId), i);
            if (percent1 != null) {
                crowdfundRanks.add(percent1);
            }
        }

        if (CollectionUtils.isNotEmpty(crowdfundRanks)) {
            for (CrowdfundRank c : crowdfundRanks) {
                if (c.getDiffTime() != null) {
                    String useTime = projectBizService.getUseTime(c.getDiffTime());
                    c.setUseTime(useTime);
                }
            }

            Collections.sort(crowdfundRanks, (o1, o2) -> o1.getPercent() > o2.getPercent() ? -1 : 1);
        }

        Map<String, Object> result = Maps.newHashMap();
        // 获取详情
        ProjectWithAuthor project = projectService.getWithAuthor(projectId);
        if (project != null) {
            int currentPercent = projectBizService.getPercent(project);
            result.put("currentPercent", currentPercent);

            double avgAmount = 0;
            if (project.getActualAmount() != 0.0 && project.getFavorerNum() != 0) {
                avgAmount = BigDecimalUtils.div(project.getActualAmount(), project.getFavorerNum(), 2);
            }
            result.put("avgAmount", avgAmount);
        }

        result.put("details", project);
        result.put("rankList", crowdfundRanks);
        result.put("allUseTime", projectBizService.getAllUseTime(projectId, null));
        return AjaxResult.success(result);
    }

    /**
     * 初始化众筹排名数据
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("initialCrowdRank")
    public AjaxResult initialCrowdRank() {
        try {
            TargetProject targetProject1 = new TargetProject();
            List<TargetProject> targetProjects = targetProjectService.list(targetProject1);
            for (TargetProject targetProject : targetProjects) {
                Activity activity = activityService.get(targetProject.getTargetId());
                Project p = projectService.get(targetProject.getProjectId());
                if (p == null) {
                    continue;
                }
                Support withMember = new Support();
                withMember.setProjectId(p.getId());
                withMember.setPayStatus(Constant.IS_SUCCESS);
                List<SupportWithMember> withMembers = supportService.listNew(withMember);
                float totalPayment = 0.0f;
                for (SupportWithMember with : withMembers) {
                    double v = BigDecimalUtils.div(totalPayment, p.getTargetAmount(), 5);
                    int beforePercent = BigDecimalUtils.amplify2int(v, 1);

                    totalPayment = BigDecimalUtils.add(with.getPayment(), totalPayment);

                    double v2 = BigDecimalUtils.div(totalPayment, p.getTargetAmount(), 5);
                    int afterPercent = BigDecimalUtils.amplify2int(v2, 1);
                    afterPercent = afterPercent > 10 ? 10 : afterPercent;
                    if (afterPercent > beforePercent) {
                        switch (afterPercent) {
                            case 1:
                            case 2:
                            case 3:
                            case 4:
                            case 5:
                            case 6:
                            case 7:
                            case 8:
                            case 9:
                            case 10:
                                projectBizService.insertCrowdRank(afterPercent, totalPayment, activity.getEventId(), targetProject.getTargetId(), with, p);
                                break;
                        }
                    }
                    int result = afterPercent - beforePercent;
                    if (result > 1) {
                        for (int i = 1; i < result; i++) {
                            projectBizService.insertCrowdRank(beforePercent + i, totalPayment, activity.getEventId(), targetProject.getTargetId(), with, p);
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error("初始化众筹排名数据异常", e);
        }
        return AjaxResult.success();
    }


    /**
     * 众筹人员了列表
     *
     * @param projectWithAuthor 查询参数
     * @param page              分页参数
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "listForActivity")
    public AjaxResult listForActivity(ProjectWithAuthor projectWithAuthor, Page page) {
        AjaxResult ajaxResult = new AjaxResult(true);
        List<ProjectForListOutput> list;
        try {
            list = projectBizService.listForActivity(projectWithAuthor, page);
        } catch (Exception e) {
            logger.error("众筹人员列表查询异常", e);
            ajaxResult.setSuccess(false);
            return ajaxResult;
        }
        ajaxResult.setData(list);
        ajaxResult.setPage(page);
        return ajaxResult;
    }


    /**
     * 查询所有主题众筹
     *
     * @param targetAuthorId 机构编号
     * @param page           分页参数
     * @param isSuccess      状态
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "listForAllSubject")
    public AjaxResult listForAllSubject(String targetAuthorId, Integer isSuccess, Page page) {
        AjaxResult ajaxResult = new AjaxResult(true);
        List<ProjectForListOutput> list;
        try {
            list = projectBizService.listForTargetAuthor(targetAuthorId, isSuccess, page);
        } catch (Exception e) {
            logger.error("查询所有主题众筹异常", e);
            ajaxResult.setSuccess(false);
            return ajaxResult;
        }
        ajaxResult.setPage(page);
        ajaxResult.setData(list);
        return ajaxResult;
    }

    /**
     * 获取众筹成功海报
     *
     * @param projectId 众筹编号
     * @return
     */
    @ResponseBody
    @RequestMapping("getProjectPoster")
    public AjaxResult getProjectPoster(String projectId) {
        long start = System.currentTimeMillis();
        if (StringUtils.isEmpty(projectId)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "众筹编号不能为空");
        }

        try {
            String posterUrl = projectBizService.getProjectPoster(projectId);
            long end = System.currentTimeMillis();
            return AjaxResult.success((end - start) / 1000 + "", posterUrl);
        } catch (BusinessException e) {
            return AjaxResult.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            return AjaxResult.error(100, "获取海报路径异常");
        }
    }

    /**
     * 众筹中的众筹__多场
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "gradation/crowdfunding")
    public AjaxResult gradationCrowdfunding(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.gradationProjectForActivityList(false, id, page);
        } catch (Exception e) {
            logger.error("获取众筹中异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 其他活动的众筹中的人列表___多场
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "gradation/crowdfundingForBrother")
    public AjaxResult gradationCrowdfundingForBrother(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.gradationProjectForBrotherList(false, id, page);
        } catch (Exception e) {
            logger.error("crowdfundingForBrother异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 众筹成功的众筹___多场
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "gradation/crowdfunded")
    public AjaxResult gradationCrowdfunded(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.gradationProjectForActivityList(true, id, page);
        } catch (Exception e) {
            logger.error("获取众筹成功数据异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 众筹成功的众筹___其他活动的众筹成功的人_____多场
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "gradation/crowdfundedForBrother")
    public AjaxResult gradationCrowdfundedForBrother(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.gradationProjectForBrotherList(true, id, page);
        } catch (Exception e) {
            logger.error("crowdfundedForBrother异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 联合发起人——众筹中的众筹__多场
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "gradation/representCrowdfunding")
    public AjaxResult gradationRepresentCrowdfunding(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.gradationProjectForRepresentList(false, id, page);
        } catch (Exception e) {
            logger.error("gradation/representCrowdfunding异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 联合发起人_所属活动事件所有众筹（众筹中）——多场
     *
     * @param id   活动编号
     * @param page 分页参数
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "gradation/crowdfundingForAll")
    public AjaxResult gradationCrowdfundingForAll(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.gradationProjectForAllList(false, id, page);
        } catch (Exception e) {
            logger.error("crowdfundingForAll异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 联合发起人_众筹成功的众筹——多场
     *
     * @param id   项目编号
     * @param page 分页参数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "gradation/represencrowdfunded")
    public AjaxResult gradationRepresencrowdfunded(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.gradationProjectForRepresentList(true, id, page);
        } catch (Exception e) {
            logger.error("represencrowdfunded异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    /**
     * 联合发起人_所属活动事件所有众筹(已经筹满)——多场
     *
     * @param id   活动编号
     * @param page 分页参数
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "gradation/crowdfundedForAll")
    public AjaxResult gradationCrowdfundedForAll(String id, Page page) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(id)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目编号不能为空");
            return ajaxResult;
        }
        List<ProjectForActivityOutput> projectForActivityOutputList = null;
        try {
            projectForActivityOutputList = projectBizService.gradationProjectForAllList(true, id, page);
        } catch (Exception e) {
            logger.error("crowdfundedForAll异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(projectForActivityOutputList);
        ajaxResult.setPage(page);
        return ajaxResult;
    }

    @Autowired
    private IMemberService memberService;

    /**
     * 众筹支持
     *
     * @param supportInput 输入视图
     * @param result       参数验证
     * @return 支持结果
     */

    @ResponseBody
    @RequestMapping(value = "test/support")
    public AjaxResult testSupport(String projectId) throws IOException {

        AjaxResult ajaxResult = new AjaxResult();

        List<String> orderids = new ArrayList<>();


        CurrentUser currentUser = new CurrentUser();
        Member member = new Member();
        member.setRealname("测试支付_");
        Page page = new Page();
        page.setLimit(3000);
        List<Member> members = memberService.partnerSimpleListPage(member, page);

        for (Member m : members) {

            currentUser.setId(m.getId());
            SupportInput supportInput = new SupportInput();
            supportInput.setMoney(1f);
            supportInput.setProjectId(projectId);

            String[] ids = projectBizService.support(supportInput, currentUser);

            orderids.add(ids[0]);
        }

        ajaxResult.setSuccess(true);
        ajaxResult.setData(orderids);
        return ajaxResult;
    }

    /**
     * 获取战队列表
     *
     * @param id   众筹编号
     * @param page 分页参数
     * @return 众筹列表
     */
    @ResponseBody
    @RequestMapping(value = "getTeams")
    public AjaxResult getTeams(String actId) {
        AjaxResult ajaxResult = new AjaxResult();
        if (Strings.isNullOrEmpty(actId)) {
            ajaxResult.setErrorCode(PartyCode.PARAMETER_ILLEGAL);
            ajaxResult.setDescription("众筹项目id不能为空");
            return ajaxResult;
        }
        Activity activity = activityService.get(actId);
        if(activity==null){
            ajaxResult.setErrorCode(PartyCode.DATA_IS_BE_DELETE);
            ajaxResult.setDescription("众筹项目不存在或众筹项目id有误");
            return ajaxResult;
        }
        List<Map<String,Object>> mmps = new ArrayList<>();
        try {
            List<Activity> activities = activityService.getActivitysByEventId(activity.getEventId());
            for (Activity a:activities){
                HashMap<String, Object> map = Maps.newHashMap();
                map.put("actId",a.getId());
                map.put("joinNum",a.getJoinNum());
                map.put("teamName",a.getPublisher());
                mmps.add(map);
            }
        } catch (Exception e) {
            logger.error("supportCrowdfunding异常", e);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(mmps);
        return ajaxResult;
    }
}
